// src/utils/avatar.ts
export function generateAvatar(text: string, size: number = 100): string {
    const canvas = document.createElement('canvas');
    canvas.width = size;
    canvas.height = size;
    const ctx = canvas.getContext('2d');

    if (ctx) {
        // 背景颜色
        ctx.fillStyle = '#3498db';
        ctx.fillRect(0, 0, canvas.width, canvas.height);

        // 文字样式
        ctx.fillStyle = '#ffffff';
        ctx.font = `${size / 2}px Arial`;
        ctx.textAlign = 'center';
        ctx.textBaseline = 'middle';

        // 绘制文字
        const firstLetter = text.charAt(0).toUpperCase();
        ctx.fillText(firstLetter, canvas.width / 2, canvas.height / 2);
    }

    return canvas.toDataURL('image/png');
}
